package com.test.mess.config;

import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.retry.policy.SimpleRetryPolicy;
import org.springframework.retry.support.RetryTemplate;

import java.util.Map;

@Configuration
public class MyConfig {

    @Value("3")
    private int retryTimes;

    @Bean
    public RetryTemplate countRetryTemplate() {
        Map<Class<? extends Throwable>, Boolean> proxyMap = Maps.newHashMap();
        proxyMap.put(Exception.class, Boolean.TRUE);
        SimpleRetryPolicy simpleRetryPolicy = new SimpleRetryPolicy(retryTimes, proxyMap);
        RetryTemplate retryTemplate = new RetryTemplate();
        retryTemplate.setRetryPolicy(simpleRetryPolicy);
        return retryTemplate;
    }
}
